<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');
/*
 * Record
 * @package	Codeigniter
 * @author	Chhing Chhing
 * @link	abc@gmail.com
 */

class Report extends PNC_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->model(array('mod_report', 'mod_employee'));
	}

	/*
	 * Index
	 * @access public
	 * @return void
	 */

	public function index() {
		redirect('report/show_report/');
	}

	public function show_report() {
		$id = $this->session->userdata('staff_id');
		if ($this->check_session()) {
			/* Total summary for each department */
			$data['app_dept_hr'] = PNC_Model::get_num_summary('approved', 'admin');
			$data['app_dept_com'] = PNC_Model::get_num_summary('approved', 'company');
			$data['app_dept_selection'] = PNC_Model::get_num_summary('approved', 'selection');
			$data['app_dept_itadmin'] = PNC_Model::get_num_summary('approved', 'itadmin');
			$data['app_dept_direction'] = PNC_Model::get_num_summary('approved', 'direction');
			$data['app_dept_wep'] = PNC_Model::get_num_summary('approved', 'wep');
			$data['app_dept_sna'] = PNC_Model::get_num_summary('approved', 'sna');
			$data['pen_dept_hr'] = PNC_Model::get_num_summary('pending', 'admin');
			$data['pen_dept_com'] = PNC_Model::get_num_summary('pending', 'company');
			$data['pen_dept_selection'] = PNC_Model::get_num_summary('pending', 'selection');
			$data['pen_dept_itadmin'] = PNC_Model::get_num_summary('pending', 'itadmin');
			$data['pen_dept_direction'] = PNC_Model::get_num_summary('pending', 'direction');
			$data['pen_dept_wep'] = PNC_Model::get_num_summary('pending', 'wep');
			$data['pen_dept_sna'] = PNC_Model::get_num_summary('pending', 'sna');
			/* Total summary for each group of department */
			$data['grp_a_hr'] = PNC_Model::get_num_group('approved', 'A', 'admin');
			$data['grp_a_com'] = PNC_Model::get_num_group('approved', 'A', 'company');
			$data['grp_a_selection'] = PNC_Model::get_num_group('approved', 'A', 'selection');
			$data['grp_a_itadmin'] = PNC_Model::get_num_group('approved', 'A', 'itadmin');
			$data['grp_a_direction'] = PNC_Model::get_num_group('approved', 'A', 'direction');
			$data['grp_a_wep'] = PNC_Model::get_num_group('approved', 'A', 'wep');
			$data['grp_a_sna'] = PNC_Model::get_num_group('approved', 'A', 'sna');
			$data['grp_b_hr'] = PNC_Model::get_num_group('approved', 'B', 'admin');
			$data['grp_b_com'] = PNC_Model::get_num_group('approved', 'B', 'company');
			$data['grp_b_selection'] = PNC_Model::get_num_group('approved', 'B', 'selection');
			$data['grp_b_itadmin'] = PNC_Model::get_num_group('approved', 'B', 'itadmin');
			$data['grp_b_direction'] = PNC_Model::get_num_group('approved', 'B', 'direction');
			$data['grp_b_wep'] = PNC_Model::get_num_group('approved', 'B', 'wep');
			$data['grp_b_sna'] = PNC_Model::get_num_group('approved', 'B', 'sna');
//			var_dump($data['grp_b_itadmin']); die();
			$data['num_a_grp'] = PNC_Model::get_num_group('approved', 'A', 'all');
			$data['num_b_grp'] = PNC_Model::get_num_group('approved', 'B', 'all');
			$data['num_other_grp'] = PNC_Model::get_num_group('approved', 'Other', 'all');
			$data['pen_a_grp'] = PNC_Model::get_num_group('approved', 'A', 'all');
			$data['pen_b_grp'] = PNC_Model::get_num_group('approved', 'B', 'all');
			$data['pen_other_grp'] = PNC_Model::get_num_group('approved', 'Other', 'all');

			$data['title'] = "Report";
			$data['employee'] = $this->mod_employee->get_employee();
			$data['total_rows'] = '';
			$data['report'] = ''; // initalize report seleted

			$emp_id = $this->uri->segment(3);
			if ($this->uri->segment(3)) {
				$data['staff'] = $this->mod_employee->get_staff($emp_id);
				$data['total_rows'] = PNC_Model::count_data('staff_id', $emp_id, 'pnc_record');
				$data['num_annual'] = $this->mod_report->num_report('annual', 1, $emp_id);
				$data['num_catchup'] = $this->mod_report->num_report('catchup', 2, $emp_id);
				$data['impossed'] = $this->mod_report->num_subtype('impossed', $emp_id);
				$data['personal'] = $this->mod_report->num_subtype('personal leave', $emp_id);
				$data['special'] = $this->mod_report->num_subtype('special leave', $emp_id);
				$data['report'] = $this->mod_report->get_report($emp_id, 'employee');
				$data['total_annual'] = $this->mod_report->sub_total($emp_id, 1, 'annual');
				$data['total_catchup'] = $this->mod_report->sub_total($emp_id, 2, 'catchup');
				$data['total_impossed'] = $this->mod_report->sub_total($emp_id, 1, 'impossed');
				$data['total_personal'] = $this->mod_report->sub_total($emp_id, 2, 'personal');
				$data['total_special'] = $this->mod_report->sub_total($emp_id, 3, 'special');
			} else {
				$data['total_rows'] = $this->mod_report->count_report_admin($id);
				$data['staff'] = $this->mod_employee->get_admin($id);
				$data['impossed'] = $this->mod_report->num_subtype('impossed', $id);
				$data['personal'] = $this->mod_report->num_subtype('personal', $id);
				$data['special'] = $this->mod_report->num_subtype('special leave', $id);
				$data['num_catchup'] = $this->mod_report->num_report('catchup', 2, $id);
				$data['num_annual'] = $this->mod_report->num_report('annual', 1, $id);
				$data['report'] = $this->mod_report->get_report($id, 'admin');
				$data['total_annual'] = $this->mod_report->sub_total($id, 1, 'annual');
				$data['total_catchup'] = $this->mod_report->sub_total($id, 2, 'catchup');
				$data['total_impossed'] = $this->mod_report->sub_total($id, 1, 'impossed');
				$data['total_personal'] = $this->mod_report->sub_total($id, 2, 'personal');
				$data['total_special'] = $this->mod_report->sub_total($id, 3, 'special');
			}
			$this->view_main($data);
		} else {
			redirect('main/');
		}
	}

	function year() {
		if ($this->check_session()) {
			$data['title'] = "Report";

			$data['staff'] = $this->mod_report->yearly_report();
			$this->view_main($data);
		} else {
			redirect('main/');
		}
	}

	function semester1() {
		if ($this->check_session()) {
			$data['title'] = "Report";
			$data['staff'] = $this->mod_report->semester_1();
			$this->view_main($data);
		} else {
			redirect('main/');
		}
	}

	function semester2() {
		if ($this->check_session()) {
			$data['title'] = "Report";
			$data['staff'] = $this->mod_report->semester_2();
			$this->view_main($data);
		} else {
			redirect('main/');
		}
	}

	function monthly() {
		if ($this->check_session()) {
			$data['title'] = "Report";
			$data['staff'] = $this->mod_report->monthly_report();
			$this->view_main($data);
		} else {
			redirect('main/');
		}
	}

	function find_date_report() {
		if ($this->check_session()) {
                    $get_report['title'] = 'Print Report';
			$date_from = $this->input->post('s_date');
			$date_to = $this->input->post('e_date');
			if ($date_from == '' && $date_to == '') {
				$this->session->set_userdata('valid', '<center style="color:red;">Two Text search can not be blank!</center>');
				redirect('report/show_report');
			} else if ($date_from > $date_to) {
				$this->session->set_userdata('valid_num', '<center style="color:red;">From file must be smaller than the To file!</center>');
				redirect('report/show_report');
			} else {
				$get_report['get_report_values'] = $this->mod_report->select_report();
				$this->load->view('master', $get_report);
			}
		} else {
			redirect('admin/');
			exit();
		}
	}

}
